﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CarLoanSystem.DAL;
using CarLoanSystem.Entity;

namespace CarLoanSystemWeb.Page.AlertMessage
{
    public partial class wuc_alerts : System.Web.UI.UserControl
    {
        private static CustomerItem cusItem;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cusItem = Session["Member"] as CustomerItem;
                BlindDataTable();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BlindDataTable();
        }

        private void BlindDataTable()
        {
            this.gvList.DataSource = AlertsMessageInfoDAL.LoadAllAlertsMessageCus(cusItem.USERNAME);
            this.gvList.DataBind();
            if (gvList.DataSource == null)
            {
                lblAlert.Visible = true;
                gvList.Visible = false;
            }
            else 
            {
                lblAlert.Visible = false;
                gvList.Visible = true;
            }
        }

        protected void gvList_EditCommand(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            Response.Redirect("ViewAlertsMessage.aspx?id=" + gvList.DataKeys[e.NewEditIndex].Values[0].ToString());
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvList.PageIndex = e.NewPageIndex;
            gvList.DataBind();
        }
    }
}